import Router from '@koa/router';
import authRoutes from './auth';
import tenantRoutes from './tenants';
import tenantPermissionRoutes from './tenant-permissions';
import userRoutes from './users';
import planRoutes from './plans';
import planPermissionRoutes from './plan-permissions'; // 套餐权限子路由
import roleRoutes from './roles';
import permissionRoutes from './permissions';
import menuRoutes from './menus';
import auditLogRoutes from './audit-logs';
import loginLogRoutes from './login-logs';
import fileRoutes from './files';
import exportImportRoutes from './export-import';
import dictionaryRoutes from './dictionaries';
import systemConfigRoutes from './system-configs';
import ossConfigRoutes from './oss-configs';
import companyRoutes from './companies';
import departmentRoutes from './departments';
import dashboardRoutes from './dashboard';
import tableConfigRoutes from './tableConfig.routes';

/**
 * 组合所有路由
 */
const router = new Router();

// 健康检查
router.get('/health', (ctx) => {
  ctx.body = {
    success: true,
    message: '服务正常运行',
    timestamp: new Date().toISOString(),
  };
});

// API 根路径
router.get('/api', (ctx) => {
  ctx.body = {
    success: true,
    message: '多租户 SaaS 平台 API',
    version: '1.0.0',
    docs: '/api/docs',
  };
});

// 注册子路由
router.use(authRoutes.routes(), authRoutes.allowedMethods());
router.use(dashboardRoutes.routes(), dashboardRoutes.allowedMethods());
router.use(tenantRoutes.routes(), tenantRoutes.allowedMethods());
router.use(tenantPermissionRoutes.routes(), tenantPermissionRoutes.allowedMethods());
router.use(userRoutes.routes(), userRoutes.allowedMethods());
router.use(planRoutes.routes(), planRoutes.allowedMethods());
router.use(planPermissionRoutes.routes(), planPermissionRoutes.allowedMethods());
router.use(roleRoutes.routes(), roleRoutes.allowedMethods());
router.use(permissionRoutes.routes(), permissionRoutes.allowedMethods());
router.use(menuRoutes.routes(), menuRoutes.allowedMethods());
router.use(auditLogRoutes.routes(), auditLogRoutes.allowedMethods());
router.use(loginLogRoutes.routes(), loginLogRoutes.allowedMethods());
router.use(fileRoutes.routes(), fileRoutes.allowedMethods());
router.use(exportImportRoutes.routes(), exportImportRoutes.allowedMethods());
router.use(dictionaryRoutes.routes(), dictionaryRoutes.allowedMethods());
router.use(systemConfigRoutes.routes(), systemConfigRoutes.allowedMethods());
router.use(ossConfigRoutes.routes(), ossConfigRoutes.allowedMethods());
router.use(companyRoutes.routes(), companyRoutes.allowedMethods());
router.use(departmentRoutes.routes(), departmentRoutes.allowedMethods());
router.use(tableConfigRoutes.routes(), tableConfigRoutes.allowedMethods());

export default router;

